package yxy.game.pm2.command.niubee;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.NiuBeeMessage;
import yxy.game.pm2.module.niubee.NiuBeeHandle;

import java.util.Date;

/** 神器 神器升级 */
@MessageType(proto = Command.NiuBeeUpgrade, classtype = NiuBeeMessage.NiuBeeUpgradeRequest.class)
public class CMD_NiuBeeUpgrade extends Command<NiuBeeMessage.NiuBeeUpgradeRequest> {

	@Override
	public void execute(MessageSource messageSource, NiuBeeMessage.NiuBeeUpgradeRequest request) {
		Date date = new Date();
		String playerCode = messageSource.getTag();

		NiuBeeMessage.NiuBeeUpgradeResponse.Builder response = NiuBeeMessage.NiuBeeUpgradeResponse.newBuilder();

		try {
			Result result = new NiuBeeHandle().upgrade(playerCode, response);
			send(messageSource, response, result);
		} catch (Exception e) {
			e.printStackTrace();
			send(messageSource, response, Result.DataError);
		}
		Date date1 = new Date();
		System.out.println("CMD_NiuBeeUpgrade:"+(date1.getTime()-date.getTime()));
	}

	private void send(MessageSource messageSource, NiuBeeMessage.NiuBeeUpgradeResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}